def convert_from_multigraph(Adj):
    V=xrange(len(Adj))
    AdjNew=[ [] for i in V ]
    for i in V:
        for j in Adj[i]:
            Adj[j].append(i)
    for i in V:
        for j in Adj[i]:
            if j>i:
                if AdjNew[j]==[] or AdjNew[j][-1]!=i:
                    AdjNew[j].append(i)
    for i in V:
        for j in Adj[i]:
            if j<i:
                if AdjNew[j]==[] or AdjNew[j][-1]!=i:
                    AdjNew[j].append(i)
    return AdjNew

if __name__=='__main__':
    Adj=[[1,2,1],[0],[1,1]]
    print Adj
    AdjNew=convert_from_multigraph(Adj)
    print AdjNew
    
